How can I parse a nested string structure into a specific parent-child format in Python